module afield
import StdEnv, japi

/* 1 -- This is the siplest of all examples. You should
   start learning the workings of JAPI using this example. */

Start world
# (js, world)= begin_japi world               // Open Japi.
# (frm,js)= jnewFrame(WH 400 300) "Ucase" js  // Create a new frame.
# (txt,js)= jnewField(XY 50 200) 30 frm js    // Create a new text field.
# msg= "Type ur stuff, and press <Enter>"     // A text
# (lb, js)= jnewLabel (XY 30 100) msg frm js  // Create a label on the frame.
# lb= jsetfont (TimesNew 20) lb               // A nicer font for the label.
# (frm,js)= jshow frm js                      // Show the frame.
# js=loop frm txt js                          // Interaction loop   
= end_japi js world                           // Close JAPI.     
where
    loop ::  !Framer !TDev !JS -> *JS
    loop frm  txt js
    # (na, js) = jnextaction js               // Read user's next event: 
    | na== (act frm) = jquit js               // If it is X-close, quit. 
    | na== (act txt)                          // If it is <Enter>,
               = loop  frm (ucase txt) js     // uppercase the field contents.
    | otherwise= loop frm  txt  js            // Otherwise, keep looping.
       
    ucase dv
    # t = jgetText dv                         // Get the text from device.
    # ut= {toUpper c \\ c <-: t}              // Convert it to uppercase.
    = jsetText dv ut                          // Put it back into the device.
        